﻿namespace Digitalmes.Application.Sys.Users.Commands;

/// <summary>
/// 更新用户信息命令。
/// </summary>
public record UpdateUserCommand(SysUserDto User) : IRequest<IResult<bool>>;

internal sealed class UpdateUserCommandHandler(IRepository<SysUser> repo) : IRequestHandler<UpdateUserCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
    {
        var user = request.User.Adapt<SysUser>();
        var ok = await repo.UpdateAsync(user, m => new
        {
            m.Nickname,
            m.Phone,
            m.Email,
            m.Gender,
            m.OrgId,
            m.LastModifiedBy,
            m.LastModifiedTime,
        }, cancellationToken);
        return Result.From(ok);
    }
}
